package me.gijspennings.jumpandduck.level;

import me.gijspennings.jumpandduck.entity.mob.Player;
import me.gijspennings.jumpandduck.graphics.Screen;
import me.gijspennings.jumpandduck.level.tiles.Tile;

public abstract class Level {
    
    protected Player player;
    protected int speed; // The amount of updates until the whole level moves 1 pixel to the left
    private int updateCount = 0;
    private int xScroll = 0, yScroll = 0;
    
    public Level(Player player, int speed) {
        this.player = player;
        this.speed = speed;
    }
    
    public void update(Screen screen) {
        player.update();
        updateCount++;
        if (updateCount >= speed) {
            xScroll = (xScroll + 1) & 15;
            screen.setOffset(xScroll, yScroll);
            updateCount = 0;
        }
    }
    public void render(Screen screen) {
        for (int y = 0; y < (screen.getAmountOfVerticalTiles() + 1); y++) {
            for (int x = 0; x < (screen.getAmountOfHorizontalTiles() + 1); x++) {
                getTile(x, y).render(screen, x, y);
            }
        }
        player.render(screen);
    }
    
    public abstract Tile getTile(int x, int y);
    
}
